#coding:utf-8
import demjson
import os
import traceback
import requests
class zmapClass():
    'zmap'
    def __init__(self, cidr,port,Band):
        '初始化'
        self.cidr = demjson.decode(cidr)
        self.port = port
        self.Band = Band

    def getblacklist(self):
        return requests.get('http://104.168.159.24/black.list').text
    def scanner(self):
        try:
            shell = 'rm -rf /var/www/html/zmap.txt'
            os.system(shell)
            shell = 'rm -rf /var/www/html/zmap'
            os.system(shell)
            shell = 'mkdir /var/www/html/zmap'
            os.system(shell)
            #黑名单文件
            bf = open('/var/www/html/zmap/b.txt','w')
            bf.write(self.getblacklist())
            bf.close()
            #白名单文件
            wf = open('/var/www/html/zmap/w.txt','w')
            wf.write('\n'.join(self.cidr))
            wf.close()
            shell = 'nohup zmap -w /var/www/html/zmap/w.txt -b /var/www/html/zmap/b.txt -o /var/www/html/zmap/out.txt -B %s -p %s >> /var/www/html/zmap.txt 2>&1 &' % (self.Band,self.port)
            os.system(shell)
        except Exception as e:
            traceback.print_exc()
            print(e)


